Ext.define('Emp.view.employee.Edit', {
	extend: 'Emp.view.BaseEdit',
	alias: 'widget.employeeedit',
	
	requires: [
		'Emp.ux.form.field.ComboTree',
		'Emp.ux.ImageUpload',
		'Emp.store.Status'
	],

	width: 430,
	height: 350,
	resizable: true,
	
	listeners: {
		'show': function() {
			this.down('filefield').el.dom.src = Ext.BLANK_IMAGE_URL;
		}
	},
	
	initComponent: function() {
		var me = this;

		me.items = [{
			xtype: 'form',
			border: false,
			layout: 'absolute',
			defaults: {
				width: 200,
				labelAlign: 'right',
				labelWidth: 50
			},
			defaultType: 'textfield',
			items: [{
					fieldLabel: 'id',
					name: 'id',
					hidden: true
				}, {
					xtype: 'imageupload',
					width: 147,
					height: 177,
					x: 240,
					y: 10,
					name: 'photo',
					src: PATH + '/resources/images/default_photo.gif'
				}, {
//					xtype: 'filefield',
//					name: 'file',
//					inputType: 'image',
//					submitValue: false,
//					//buttonOnly: true,
//					buttonText: '',
//					buttonConfig: {
//		                iconCls: 'upload-icon'
//		            },
//		            x: 387,
//					y: 187,
//					listeners: {
//						scope: me,
//						'change': function(field, value) {
//							//this.down('image').setLoading(true);
//						}
//					}
//				}, {
					fieldLabel: 'enName',
					name: 'enName',
					x: 0,
					y: 10,
					allowBlank: false
				}, {
					fieldLabel: 'cnName',
					name: 'cnName',
					x: 0,
					y: 40,
					allowBlank: false
				}, {
					fieldLabel: 'sex',
		            name: 'sex',
		            xtype: 'combobox',
					store: Ext.create('Ext.data.Store', {
					    fields: ['display', 'value', 'status'],
					    data: Emp.getDictionarys('sex')
					}),
					listConfig: {
						getInnerTpl: function() {
							return '<tpl if="status == \'enable\'"><div>{display}</div><tpl else><div class="disable-status" data-qtip="已停用">{display}</div></tpl>';
						},
						listeners: {
							itemclick: function(view, record) {
								if(record.get('status') === 'enable') {
									view.selModel.locked = false;
								} else {
									view.selModel.locked = true;
								}
							}
						}
				    },
					queryMode: 'local',
					displayField: 'display',
					valueField: 'value',
					forceSelection: true,
					x: 0,
					y: 70,
					allowBlank: false
				}, {
					fieldLabel: 'idCard',
					name: 'idCard',
					x: 0,
					y: 100,
					allowBlank: false
				}, {
					fieldLabel: 'phone',
					name: 'phone',
					x: 0,
					y: 130,
					allowBlank: false
				}, {
					fieldLabel: 'education',
		            name: 'education',
		            xtype: 'combobox',
					store: Ext.create('Ext.data.Store', {
					    fields: ['display', 'value', 'status'],
					    data: Emp.getDictionarys('education')
					}),
					listConfig: {
						getInnerTpl: function() {
							return '<tpl if="status == \'enable\'"><div>{display}</div><tpl else><div class="disable-status" data-qtip="已停用">{display}</div></tpl>';
						},
						listeners: {
							itemclick: function(view, record) {
								if(record.get('status') === 'enable') {
									view.selModel.locked = false;
								} else {
									view.selModel.locked = true;
								}
							}
						}
				    },
					queryMode: 'local',
					displayField: 'display',
					valueField: 'value',
					forceSelection: true,
					x: 0,
					y: 160,
					allowBlank: false
				}, {
					xtype: 'datefield',
					fieldLabel: 'inDate',
					name: 'inDate',
					format: 'Y-m-d',
					x: 0,
					y: 190,
					allowBlank: false
				}, {
					xtype: 'datefield',
					fieldLabel: 'outDate',
					name: 'outDate',
					format: 'Y-m-d',
					x: 0,
					y: 220,
					allowBlank: false
				}, {
					fieldLabel: '状态',
		            name: 'status',
		            xtype: 'combobox',
					store: Ext.create('Emp.store.Status'),
					queryMode: 'local',
					displayField: 'display',
					valueField: 'value',
					forceSelection: true,
					x: 0,
					y: 250,
					allowBlank: false
				}, {
					xtype: 'combotree',
					fieldLabel: '部门',
					name: 'deptId',
					treeConfig: {
						useArrows: true,
						rootVisible: false
					},
					displayField: 'cnName',
					valueField: 'id',
					store: Ext.create('Emp.store.DeptNode', {
						proxy: {
							type: 'ajax',
							url: PATH + '/dept/stree'
						}
					}),
					forceSelection: true,
					x: 200,
					y: 220,
					allowBlank: false
				}, {
					xtype: 'numberfield',
					fieldLabel: '排序',
					name: 'sort',
					hideTrigger: true,
					allowDecimals:false,
					x: 200,
					y: 250,
					allowBlank: false
//				}, {
//					fieldLabel: 'photo',
//					name: 'photo',
//					hidden: true,
//					listeners: {
//						scope: me,
//						'change': function(field, value) {
//							if(value !== '') {
//								this.down('image').setSrc(Emp.dir.images + value);
//							}
//						}
//					}
				}]
		}];
		me.callParent();
	}
});